package com.example.logserver.controller;


import com.alibaba.fastjson.JSON;
import com.example.logserver.entity.Log;
import com.example.logserver.service.ILogService;
import com.org.dto.LogDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

/**
 * <p>
 * 系统日志表 前端控制器
 * </p>
 *
 * @author xc
 * @since 2021-11-22
 */
@Slf4j
@RabbitListener(queues = "mylogA")
@Component
public class LogController {

    @Autowired
    private ILogService logService;

    @RabbitHandler
    public void saveLog(String s){
        LogDto logDto = JSON.parseObject(s, LogDto.class);
        Log mylog = new Log();
        BeanUtils.copyProperties(logDto,mylog);
        mylog.setCreateDate(LocalDate.now());
        log.info("------------接受日志消息--------");
        logService.save(mylog);

    }

}
